<?php

class Model_DbTable_Klacht extends Zend_Db_Table_Abstract
{

	protected $_name = 'klacht'; //dit je naam van je table in je database

	public function deleteKlacht($callid) {
		
		$where = $this->getAdapter()->quoteInto( 'callid = ?', intval( $callid ) );  //voorkomt sql injection doordat het een integer getal verwacht en de eventuele hostile code wordt als string verwerkt ipv code
		$this->delete( $where );
		
	}
	
	public function updateKlacht($callid = 0, $data) {
	    
	    if($callid === 0){
	        throw new exception('Update failed missing alot of parameters');
	    } else {
	        $where = $this->getAdapter()->quoteInto( 'id = ?', intval( $callid ) );
			$this->update( $data, $where ); 
	    }
        
	
	}
	
	public function fetchUserKlachten($userid = 0)
	{
		
		if($userid === 0){
			throw new exception('Fetch failed missing alot of parameters');
		} else {
			
			$where = $this->getAdapter()->quoteInto( 'klachtEigenaar = ?', intval( $userid ) );
			$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
							->setIntegrityCheck(false)
							->joinLeft('klachtstatus','klachtstatus.id = klacht.klachtStatus', array("statusname" => "klachtStatus"))
							->where($where);
			$data = $this->fetchAll($select);	
			//die("<pre>" . print_r($data,1) . "</pre>");
		}
		
		return $data;
		
	}
	
	public function fetchAllKlachten()
	{
			
		$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
						->setIntegrityCheck(false)
						->joinLeft('klachtstatus','klachtstatus.id = klacht.klachtStatus', array("statusname" => "klachtStatus"))
						->joinLeft('configuratie','configuratie.id = klacht.klachtConfig', array("configname" => "configNaam"));
		//die($select->__toString());				
		$data = $this->fetchAll($select);	
		
		return $data;
		
	}
	
	public function fetchMedewerkerKlachten($klachtStatus = 0)
	{
		
		if($klachtStatus !== 0) {
			$where = $this->getAdapter()->quoteInto( 'klacht.klachtStatus = ?', intval( $klachtStatus ) );
			$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
							->setIntegrityCheck(false)
							->joinLeft('klachtstatus','klachtstatus.id = klacht.klachtStatus', array("statusname" => "klachtStatus"))
							->joinLeft('configuratie','configuratie.id = klacht.klachtConfig', array("configname" => "configNaam"))
							->joinLeft('klachttype','klachttype.id = klacht.klachtType', array("klachttype" => "klachtType"))
							->joinLeft('user','user.id = klacht.klachtBehandelaar', array("username" => "username"))
							->where($where);
			
			//die($select->__toString());
			$data = $this->fetchAll($select);	
			return $data;
			
		} else {
			return false;
		}
		
		
		
		
	}
	

	/*
	public function fetchAllMedewerkers()
	{
		$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
						->setIntegrityCheck(false)
						->joinLeft('klachtMedewerker','userType.id = klacht.klachtMedewerker', array("medewerkers" => "klachtMedewerker"));

		$data = $this->fetchAll($select);	
		
		return $data;

	}
	*/
}	
	
	
	



